package collection;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class SortListDemo2 {
    public static void main(String[] args) {
        List<Point> list = new ArrayList<>();
        list.add(new Point(3, 6));
        list.add(new Point(77, 65));
        list.add(new Point(32, 16));
        list.add(new Point(33, 60));
        list.add(new Point(28, 44));
        list.add(new Point(76, 17));
        System.out.println(list);

        //Collections.sort(list);
        //System.out.println(list);

//        Comparator<Point> comparator = new Comparator<Point>() {
//            @Override
//            public int compare(Point o1, Point o2) {
//                int i1 = o1.getX() * o1.getX() + o1.getY() * o1.getY();
//                int i2 = o2.getX() * o2.getX() + o2.getY() * o2.getY();
//                return i1 - i2;
//            }
//        };
        Collections.sort(list, new Comparator<Point>() {
            @Override
            public int compare(Point o1, Point o2) {
                int i1 = o1.getX() * o1.getX() + o1.getY() * o1.getY();
                int i2 = o2.getX() * o2.getX() + o2.getY() * o2.getY();
                return i1 - i2;
            }
        });
        System.out.println(list);

    }
}
